import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sainbainu/common/values/colors.dart';
import 'package:sainbainu/common/widgets/keyboard_close.dart';

/// 取消-标题-确认的页面容易 多用于选择器弹窗
class CancelConfirmWrapper extends StatelessWidget {
  final Widget child;

  /// 标题文字与自定义
  final String? titleText;
  final Widget? titleChild;

  /// 默认取消、确认文字
  final Widget? cancelChild;
  final Widget? confirmChild;

  /// 默认取消、确认按钮央视
  final ButtonStyle? cancelStyle;
  final ButtonStyle? confirmStyle;

  /// 自定义取消、确认按钮
  final Widget? customCancel;
  final Widget? customConfirm;

  /// 点击取消、确认回调
  final VoidCallback? onCancelTap;
  final VoidCallback? onConfirmTap;

  const CancelConfirmWrapper({
    super.key,
    required this.child,
    this.titleText,
    this.titleChild,
    this.cancelChild,
    this.confirmChild,
    this.cancelStyle,
    this.confirmStyle,
    this.onCancelTap,
    this.onConfirmTap,
    this.customCancel,
    this.customConfirm,
  });

  @override
  Widget build(BuildContext context) {
    return KeyboardClose(
      child: Scaffold(
        appBar: AppBar(
          title: titleChild ?? Text(titleText ?? ''),
          leading: customCancel ??
              TextButton(
                onPressed: onCancelTap,
                style: cancelStyle ??
                    TextButton.styleFrom(
                      foregroundColor: AppColors.active,
                    ),
                child: cancelChild ?? Text('取消'.tr),
              ),
          leadingWidth: kToolbarHeight * 1.5,
          actions: [
            customConfirm ??
                SizedBox(
                  width: kToolbarHeight * 1.5,
                  height: kToolbarHeight,
                  child: TextButton(
                    onPressed: onConfirmTap,
                    style: confirmStyle ??
                        TextButton.styleFrom(
                          foregroundColor: AppColors.danger,
                          enableFeedback: true,
                        ),
                    child: confirmChild ?? Text('确定'.tr),
                  ),
                ),
          ],
          scrolledUnderElevation: 0,
        ),
        body: child,
      ),
    );
  }
}
